package com.delivery.mapper;

import com.delivery.annotation.AutoFill;
import com.delivery.dto.DishPageQueryDTO;
import com.delivery.entity.Dish;
import com.delivery.enumeration.OperationType;
import com.delivery.vo.DishVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DishMapper {
    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 插入菜品数据
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 分页查询菜单信息
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据id获取Dish菜品信息
     * @param id
     * @return
     */
    @Select("SELECT * FROM dish where id = #{id}")
    Dish getById(Long id);


    /**
     * 根据id删除Dish菜品信息
     * @param id
     */
    @Delete("DELETE from dish where id = #{id}")
    void deleteById(Long id);

    /**
     * 更新菜品信息
     * @param dish
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 菜品表左连接于根据id获取到的对应菜品信息，返回更多关于菜品信息
     * @param id
     * @return
     */
    List<Dish> getBySetmealId(Long id);

    /**
     * 根据dish获取到List
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);
}
